package svc

import (
	"mail/service/account/rpc/accountclient"
	"mail/service/outlay/model"
	"mail/service/outlay/rpc/internal/config"
	"mail/service/receipt/rpc/receiptclient"

	"github.com/zeromicro/go-zero/core/stores/sqlx"
	"github.com/zeromicro/go-zero/zrpc"
)

type ServiceContext struct {
	Config      config.Config
	OutlayModel model.OutlayModel
	AccountRpc  accountclient.Account
	ReceiptRpc  receiptclient.Receipt
}

func NewServiceContext(c config.Config) *ServiceContext {
	return &ServiceContext{
		Config:      c,
		OutlayModel: model.NewOutlayModel(sqlx.NewMysql(c.Mysql.DataSource), c.CacheRedis),
		AccountRpc:  accountclient.NewAccount(zrpc.MustNewClient(c.AccountRpc)),
		ReceiptRpc:  receiptclient.NewReceipt(zrpc.MustNewClient(c.ReceiptRpc)),
	}
}
